#pragma once

#include <AVUIToggleButton.h>

namespace AVUI {

class RadioButton;

class ControlTemplate;
class RadioButton : public ToggleButton
{
public:
    RadioButton() { };
    ~RadioButton();

    DECLARE_ELEMENT(RadioButton, ToggleButton);


    DECLARE_DEPENDENCY_PROPERTY(GroupName);
    TRefCountedPtr<String> get_GroupName() { return (String*)(Object*)GetValue(get_GroupNameProperty()); }
    void set_GroupName(String* pValue) { SetValue(get_GroupNameProperty(), (Object*)pValue); } 

protected:
    virtual void OnToggle();
    virtual void OnChecked(RoutedEventArgs* pArgs);

private:
    static void StaticConstructor();

    struct GroupItem
    {
        TRefCountedPtr<String> GroupName;
        TRefCountedPtr<ItemStructList<RadioButton* > > GroupMembers;
    };

    static ItemStructList<GroupItem> m_registeredGroups;

    static void OnGroupNameChanged(DependencyObject* pDO, DependencyPropertyChangedEventArgs* e);
    void UpdateRadioButtonGroup();
    static void AddToGroup(RadioButton* pButton, String* pGroup);
    static void RemoveFromGroup(RadioButton* pButton, String* pGroup);
    static GroupItem* GetItemForGroupName(String* pGroup);
};

}; // namespace AVUI
